Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a data race in the Go JSON-RPC client by converting the running field from a plain bool to atomic.Bool. The race occurred because the field was accessed concurrently by the Stop() method and the background readLoop() goroutine without synchronization. The PR also enables the Go race detector in the test script to catch such issues in future CI runs.
Changes:
- Changed
runningfield frombooltoatomic.Booland updated all access points to use atomic operations (Store(),Load()) - Enabled the
-raceflag ingo testcommand to detect data races in CI
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| go/test.sh | Added -race flag to enable Go's race detector during test execution |
| go/internal/jsonrpc2/jsonrpc2.go | Fixed data race by converting running field to atomic.Bool and using atomic operations for all accesses |
|
Thanks for contributing this, @chlowell! I notice that CI is failing with this change due to it detecting another data race: from https://github.com/github/copilot-sdk/actions/runs/22418728180/job/65004395091?pr=586 If we're adding this detection, could you also update other places that would trigger it? Thanks! |
|
Sorry I missed that one; I haven't been able to repro it on my machine with the current test suite. I added a test that reliably triggers it and other races in |
The client's
running boolfield is accessed concurrently byStop()andreadLoop()methods without synchronization, creating a data race. This can be prevented by simply changing the field's type toatomic.Bool. I also enabled thego testrace detector in the test script so future CI runs will fail when the test suite triggers a race.